<!DOCTYPE html>
<html>

<head>

    {include file="common:meta"}

</head>
<style>
    .btn-primary{

    }

</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <form method="" class="form-horizontal" id="form" action="">
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label" for="type">
                                <span class="c-red">*</span>合成奖品类别：
                            </label>
                            <div class="col-md-2 col-sm-10">
                                <select class="form-control" name="type" id="type">
                                    <option value="">--请选择--</option>
                                    <option value="1">座驾</option>
                                    <option value="2">礼物</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label" for="type_id">
                                <span class="c-red">*</span>合成奖品名称：
                            </label>
                            <div class="col-md-2 col-sm-10">
                                <select class="form-control" name="type_id" id="type_id">
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*所需卡片数量</label>
                            <div class="col-sm-10">
                                <input type="number" name="card_num" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*状态
                            </label>
                            <div class="col-sm-10">
                                <div class="radio">
                                    <label><input type="radio"  name="status" value="0"> <i></i> 禁止用户合成</label>
                                    </div>
                                <div class="radio">
                                    <label><input type="radio" name="status"  value="1"> <i></i> 开放用户合成</label>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <div class="col-sm-10">
                                <input type="hidden" name='rule_id' value="{$id}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <input class="btn btn-primary" id="btn-submit" type="button" value="提交">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script>
    //同意申请
    var index = parent.layer.getFrameIndex(window.name);
    $('#btn-submit').click(function(){
        layer.confirm('确定修改吗？',{
            title:['提示','font-size:18px;font-family:楷体;font-weight:700;'],
            btn: ['确定','取消'] //按钮
        },function(){
            $.ajax({
                type:'get',
                url:'/CardRuleEdit',
                async:true,
                data:$('#form').serialize(),
                dataType:'json',
                success:function(result){
                    console.log(result);
                    if(result.code == 100){
                     //   parent.layer.close(index);//关闭当前页
                        layer.msg(result.msg,{
                            icon:1,
                            time:1000
                        });

                        //$('#tb_departments',parent.window.document).reload();
                        setTimeout(function () {
                            parent.layer.close(index);// 关闭layer
                        },1500);

                        //window.parent.parent.location.replace(location.href);
                        //$('#tb_departments',parent.window.document).bootstrapTable(('refresh'));

                       // window.parent.location.replace(location.href)//刷新父级页面
//                        $('#tb_departments').bootstrapTable(('refresh'));
//                        $('#batch-deal-with').css('display','none');
                    }
                    else{
                        layer.msg(result.msg,{
                            icon:2,
                            time:1000
                        });
                    }
                },
                error:function(err){
                    layer.msg('服务器开小差了！',{
                        time:1500
                    });
                }
            });
        });
    });


    function changeStatus(url, row, obj) {
        var status = row.status === 1 ? '开放用户合成' : '禁止用户合成';
        row.status === 1 ? row.status = 0 : row.status = 1;
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: url,
            data: {'id': row.id},
            success: function (re) {
                if (re.code === 200) {
                    layer.msg(re.msg, {icon: 1, time: 2000});
                    $(obj).html(status);
                } else {
                    layer.alert(re.msg);
                }
            },
            error: function (data) {
                console.log(data.msg);
            }
        });
    }

    //二级联动
    $(document).ready(function(e) {
        ChangeType();
        $("#type").change(function(){
            ChangeType();
        });
        $("#typed_id").change(function(){
            ChangeGift();
        })
    });
    function ChangeType(){
        var type = $('#type').val();
        // console.log(type);
        $.ajax({
            async:false,
            url:"/CardRuleGiftName",
            data:{type:type},
            type:"post",
            dataType:"TEXT",
            success:function(res){
                //  var hang = data.split("|");
                var data = JSON.parse(res);

                console.log(data);
                var str = "<option value='' selected>--请选择--</option>";
                if(data != null){
                    for(var i in data){
                        str+= "<option value="+data[i]['id']+">"+data[i]['gift_name']+"</option>";
                    }
                    // for(var i=0;i<data.length;i++){
                    //     str += "<option value="+data[i].id+">"+data[i].gift_name+"</option>";
                    // }
                }
                $("#type_id").html(str);
            }
        });
    }
    function ChangeGift(){
        var giftId = $("#type_id").val();
//        var postData = $('#form').serialize();
//        console.log(giftId);
//        console.log(postData);
    }

</script>
</body>

</html>